#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
# Copyright 2018-2019, Intel Corporation
#
#
# pmempool_check/TEST32 -- test for check command with badblocks
#                          - bad blocks in the dax device
#

. ../unittest/unittest.sh

require_test_type medium
require_build_type debug nondebug

require_badblock_tests_enabled dax_device
require_linked_with_ndctl $PMEMPOOL$EXESUFFIX

setup

. ../common_badblock.sh

badblock_test_init dax_device

LOG=out${UNITTEST_NUM}.log
rm -f $LOG && touch $LOG

POOLSET=$DIR/testset1
create_poolset $POOLSET AUTO:$FULLDEV:x \
			R 10M:$DIR/testfile1:z

expect_normal_exit $PMEMPOOL$EXESUFFIX rm $POOLSET
expect_normal_exit $PMEMPOOL$EXESUFFIX create obj --layout pmempool$SUFFIX $POOLSET

turn_on_checking_bad_blocks $POOLSET

# inject bad block: OFF=11 LEN=8
ndctl_inject_error $NAMESPACE 11 8

expect_bad_blocks $NAMESPACE

expect_abnormal_exit "$PMEMPOOL$EXESUFFIX check -v $POOLSET >> $LOG"

expect_bad_blocks $NAMESPACE

ndctl_uninject_error $FULLDEV $NAMESPACE 11 8

badblock_test_fini

check

pass
